package com.cal.calonecal.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cal.calonecal.common.Response;
import com.cal.calonecal.pojo.dto.CreateClassDTO;
import com.cal.calonecal.pojo.entity.ClassRoom;
import com.cal.calonecal.pojo.entity.UserInfo;
import com.cal.calonecal.service.impl.ClassRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 76004
 * @apiNote
 * @date 2023/6/10 17:45
 */
@RequestMapping("/class")
@RestController
@Api("班级相关")
@CrossOrigin
public class ClassRoomController {
    @Autowired
    private ClassRoomService classRoomService;

    @PostMapping("/create")
    @ApiOperation("创建班级")
    public Response<Void> createClass(@RequestBody CreateClassDTO createClassDTO){
        return classRoomService.createClass(createClassDTO);
    }

    @GetMapping("/get-students")
    @ApiOperation("获取班级学生")
    public Response<IPage<UserInfo>>getStudents(Long classId, Integer pageSize, Integer pageNum){
        return classRoomService.getStudents(classId, pageSize, pageNum);
    }

    @DeleteMapping("/delete-class")
    @ApiOperation("删除班级")
    public Response<Void>deleteClass(Long classId){
        return classRoomService.deleteClass(classId);
    }

    @GetMapping("/get-classes")
    @ApiOperation("查询用户所在班级列表，当userId为0时查询所有班级")
    public Response<IPage<ClassRoom>>getClassRooms(Integer pageSize, Integer pageNum, Long userId){
        return classRoomService.getClassRooms(pageSize, pageNum, userId);
    }

    @PutMapping("/update-class-status")
    @ApiOperation("更改班级状态，1表示被封禁, 2表示隐藏，0表示可见")
    public Response<Void>banClass(Long classId, Integer status){
        return classRoomService.updateClassStatus(classId, status);
    }

    @PutMapping("/join")
    @ApiOperation("加入班级")
    public Response<Void>joinClass(Long classId){
        return classRoomService.joinClass(classId);
    }

    @DeleteMapping("/remove-student")
    @ApiOperation("将学生从班级移除")
    public Response<Void>removeStudent(Long userId, Long classId){
        return classRoomService.removeStudent(userId, classId);
    }

    @DeleteMapping("/exit-class")
    @ApiOperation("退出班级")
    public Response<Void>exitClass(Long classId){
        return classRoomService.exitClass(classId);
    }

    @PutMapping("/update")
    public Response<Void>updateClass(@RequestBody ClassRoom classRoom){
        return classRoomService.updateClass(classRoom);
    }

    @GetMapping("/select-by-teacher-id")
    @ApiOperation("获取我创建的班级")
    public Response<IPage<ClassRoom>> selectByTeacherId(Integer pageNum, Integer pageSize) {
        return classRoomService.selectByTeacherId(pageNum, pageSize);
    }

}
